#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>

int global = 0;
pthread_mutex_t mutex;
void* start(void *arg)
{
	int ret;
	//pthread_mutex_t mutex;
	//pthread_mutex_init(&mutex,NULL);

	ret = pthread_mutex_lock(&mutex);
	if(ret)
	{
		printf("The mutex is used!\n");
	}
	int i=0;
	for(i=0;i<10000000;i++)
		global++;
	ret = pthread_mutex_unlock(&mutex);
	if(ret)
	{
		printf("error");
	}
	pthread_exit(0);
}

int main()
{
	pthread_t tid1,tid2;
	int ret;
	pthread_mutex_init(&mutex,NULL);
	ret = pthread_create(&tid1,NULL,start,NULL);
	if(ret)
	{
		printf("error!\n");
		exit(0);
	}
	
	ret = pthread_create(&tid2,NULL,start,NULL);
	if(ret)
        {
                printf("error!\n");
                exit(0);
        }
	pthread_join(tid1,NULL);
	pthread_join(tid2,NULL);

	printf("total is %d \n",global);
}
